第7回日本情報オリンピック C - ダーツ
提出
WA
code: python
from bisect import bisect_left
n, m = map(int, input().split())
score.sort()
total = 0
first_idx = bisect_left(score, m-total)
if (first_idx == 0):
print(total)
exit()
second_idx = bisect_left(score, m-total)
if (second_idx == 0):
print(total)
exit()
third_idx = bisect_left(score, m-total)
if (third_idx == 0):
print(total)
exit()
forth_idx = bisect_left(score, m-total)
if (forth_idx == 0):
print(total)
exit()
print(total)
解答
code: python
from bisect import bisect_right
n, m = map(int,input().split())
# 取れない得点は排除
score = [scorei for i in range(n) if scorei <= m] score.sort()
n = len(score)
# 1,2の合計
score_1_2 = set()
for i in range(n):
for j in range(n):
score_1_2.add(scorei + scorej) score_1_2 = list(score_1_2)
score_1_2.sort()
# 1,2の最大
ans = max(score-1, score_1_2-1) # 3の最大
for i in range(n):
# 足せる最大の得点のインデックス
idx = bisect_right(score_1_2, m - scorei) - 1 if idx != -1:
ans = max(ans, scorei + score_1_2idx) # 4の最大
for i in score_1_2:
idx = bisect_right(score_1_2, m - i) - 1
if idx != -1:
ans = max(ans, i + score_1_2idx) print(ans)
テーマ
提出
TLE
code: python
from itertools import product
n, m = list(map(int, input().split()))
p.append(0)
ans = -1
for i in product(p, repeat=4):
res = sum(i)
if res <= m and res > ans:
ans = res
print(ans)
解答
code: python
import bisect
n, m = map(int, input().split())
p.append(0)
s = sorted(pi + pj for i in range(n + 1) for j in range(n + 1)) res = 0
for a in s:
# M - a以下の最大の値のインデックス
index = bisect.bisect_left(s, m - a + 1) - 1
if index >= 0:
res = max(res, a + sindex) print(res)
メモ